﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TaskBasedSchedule.Core
{
    public class Database : IDisposable
    {
        public DatabaseType Type { get; private set; }

        public System.Data.IDbConnection Connection { get; private set; }

        public void Close()
        {
            if (Connection != null)
                Connection.Close();
        }

        internal Database(DatabaseType type, System.Data.IDbConnection connection)
        {
            if (connection == null)
                throw new ArgumentException("Argument `connection` should not be null");
            Type = type;
            Connection = connection;
        }

        public void Dispose()
        {
            Connection.Dispose();
        }

        ~Database()
        {
            if (Connection != null)
            {
                Connection.Close();
                Connection = null;
            }
        }
    }
}